<template>
  <v-dialog
    persistent
    :content-class="contentClass"
    v-bind="$attrs"
    v-on="$listeners"
    :value="showValue"
  >
    <div class="head">
      <slot name="header">
        <div class="title">
          <div>
            <slot name="title">{{ propTitle }}</slot>
          </div>
          <div class="icon-group d-flex align-center">
            <slot
              name="headerAppend"
              :close="closeDialog"
              :submit="submitDialogInfo"
            >
              <v-tooltip bottom>
                <template v-slot:activator="{ on, attrs }">
                  <v-btn
                    v-show="propShowSave"
                    v-on="on"
                    v-bind="attrs"
                    @click="submitDialogInfo"
                    class="mr-4"
                    width="18"
                    height="18"
                    icon
                  >
                    <v-icon class="icon save pointer">
                      mdi-content-save
                    </v-icon>
                  </v-btn>
                </template>
                <span>save</span>
              </v-tooltip>
              <v-tooltip bottom>
                <template v-slot:activator="{ on, attrs }">
                  <v-btn
                    v-on="on"
                    v-bind="attrs"
                    @click="closeDialog"
                    width="18"
                    height="18"
                    icon
                  >
                    <v-icon class="icon close pointer"> mdi-close </v-icon>
                  </v-btn>
                </template>
                <span>Close Dialog</span>
              </v-tooltip>
            </slot>
          </div>
        </div>
      </slot>
    </div>
    <div class="dialog-content">
      <slot name="default"> dialog-content </slot>
    </div>
  </v-dialog>
</template>

<script lang="ts">
import { Component, Vue, ModelSync } from "vue-property-decorator";
@Component({
  components: {},
  props: {
    title: String,
    "show-save": {
      type: Boolean,
      default: true,
    },
  },
})
export default class Dialog extends Vue {
  @ModelSync("value", "input", { type: Boolean }) showValue!: boolean;

  get propShowSave() {
    return this.$props.showSave;
  }

  get contentClass() {
    return `elevation-0 dialog-container ${this.$attrs["content-class"] ?? ""}`;
  }

  get propTitle() {
    return this.$props.title;
  }

  submitDialogInfo() {
    this.$emit("submit");
  }

  closeDialog() {
    this.showValue = false;
    this.$emit("close");
  }
}
</script>

<style lang="scss">
@import "./Dialog.scss";
</style>
